﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Abs.Core;

namespace Abs.App
{
    public partial class WebForm1 : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            //Stop users from loging in twice
            if(Session["Email"] != null)
                Response.Redirect("~/Default.aspx");
        }


        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            var userManagement = Abs.Core.Management.Manage.User;
            var user = userManagement.LogIn(Text_Email.Text, Text_Password.Text);
            if (user == null)
            {
                Response.Redirect("~/User/Login.aspx");
            }
            else
            {
                Session["Name"] = user.Name;
                Session["Email"] = user.Email;
                Session["Role"] = user.RoleId;
                Response.Redirect("~/Default.aspx");
            }
            
        }


    }
}